package com.yy.try_;

import com.yy.exception_.ArrayIndexOutOfBoundsException_;

/**
 * chapter12  com.yy.try_
 * 2023-05-10 09:14
 *
 * @author yy yuyue
 * description : 不可描述
 * @date 2023/5/10 9:14
 */
public class TryCatchExercise01 {
}

class Exception01{
    public static int method(){
        try {
           String[] names = new String[3];//String[] 数组
           if(names[1].equals("tom")){// NullPointerException
               System.out.println(names[1]);
           }else {
               names[3] = "yy";
           }
           return 1;
        }catch (ArrayIndexOutOfBoundsException e){
            return 2;
      }catch (NullPointerException e){//捕获
         return 3;
    }finally {//必须执行
            return 4;//返回4
        }
    }

    public static void main(String[] args) {
        System.out.println(method());
    }
}